package com.gitee.chili.leisure.message;

import com.gitee.chili.leisure.core.AbstractDefaultMessage;
import com.gitee.chili.leisure.core.Packet;
import com.gitee.chili.leisure.model.BaseMessageModel;
import com.gitee.chili.leisure.model.MessageCmdEnum;
import com.gitee.chili.leisure.util.Connection;
import com.google.protobuf.InvalidProtocolBufferException;
import io.netty.channel.Channel;

/**
 * Logout
 *
 * @author week solider
 * @since 2020.08.31
 */
public class Logout extends AbstractDefaultMessage {


    public Logout(Packet packet, Channel channel) {
        super(packet, channel);
    }

    @Override
    protected void decoder(byte[] body) throws InvalidProtocolBufferException {
        BaseMessageModel.Logout logout = BaseMessageModel.Logout.parseFrom(body);
        // TODO 写入登出时间
        long timestamp = logout.getTimestamp();// 登出时间
    }

    @Override
    public Packet parseBody() {
        // 清空所有缓存
        Connection.broadcaster().remove(getChannel());
        return Packet.newPacket(MessageCmdEnum.Command.LOGOUT, new byte[0]);
    }
}
